package chapter6.eg8;

import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.junit.Test;

public class ChannelFutureListenerExample {
  @Test
  public void testAddListenerThroughChannelFuture() {
    Channel channel = new NioServerSocketChannel();
    ChannelFuture future = channel.write("msg");
    future.addListener(new ChannelFutureListener() {
      public void operationComplete(ChannelFuture future) throws Exception {
        if (!future.isSuccess()) {
          future.cause().printStackTrace();
          future.channel().close();
        }
      }
    });
  }
}
